
CC      = gcc
CPP     = g++
#-Wmaybe-uninitialized
CFLAGS += -O1 -g -Wall -std=c++11  #--no-whole-archive -fsanitize=address -fno-omit-frame-pointer  
DFLAGS =                                #-DHAVE_CONFIG_H=1  #宏定义
LIBRARIES =  -lpthread  -lrt              #链接库-lasan
INC_DIR = -I./TinyTimer  -I./ -I./LowPower -I./SystemTime -I./SystemTime/Timer -I./ATCMD   -I./Communication -I./Epoll -I./History -I./Log -I./MsgCom  -I./HotPlug  -I./Peripheral/Serial  -I./Ringbuffer -I./Verification/CRC   #头文件路径	
BIN = msgcenter             #生成的固件名
MAINSRC = main_tinytimer.c         #主源文件

#查找所有源文件
ROOT_PATH = $(shell pwd)
$(info $(ROOT_PATH) )
DIRS := $(ROOT_PATH)/Communication
DIRS += $(ROOT_PATH)/Epoll
DIRS += $(ROOT_PATH)/History
DIRS += $(ROOT_PATH)/Log
DIRS += $(ROOT_PATH)/MsgCom
DIRS += $(ROOT_PATH)/HotPlug
DIRS += $(ROOT_PATH)/Ringbuffer
CDIRS := $(ROOT_PATH)/Peripheral/Serial
CDIRS += $(ROOT_PATH)/Verification/CRC
CDIRS += $(ROOT_PATH)/SystemTime
CDIRS += $(ROOT_PATH)/SystemTime/Timer
CDIRS += $(ROOT_PATH)/Log
CDIRS += $(ROOT_PATH)/ATCMD
CDIRS += $(ROOT_PATH)/IPC/FIFO
CDIRS += $(ROOT_PATH)/IPC/Pipe
CDIRS += $(ROOT_PATH)/IPC/Sem
CDIRS += $(ROOT_PATH)/IPC/ShareMem
CDIRS += $(ROOT_PATH)/LowPower
CDIRS += $(ROOT_PATH)/TinyTimer
SRCS := $(basename $(foreach dir,$(DIRS),$(wildcard $(dir)/*.cpp)))#其他源文件
SRCS += $(basename $(foreach dir,$(CDIRS),$(wildcard $(dir)/*.c)))

#目标文件
OBJEXT ?= .o   #目标文件类型
SUB_OBJ = $(addsuffix .o,$(SRCS))
MAINOBJ = $(MAINSRC:.c=$(OBJEXT))


#make all时执行后面所有的
all: default


#make自动规划将所有源文件编译成目标文件
%.o: %.cpp
	@$(CPP)  $(CFLAGS) $(DFLAGS) $(INC_DIR) -c $< -o $@

%.o: %.c
	@$(CC)   $(CFLAGS) $(DFLAGS) $(INC_DIR) -c $< -o $@

#make 执行此处 make不加参数时执行此处
default:$(SUB_OBJ) $(MAINOBJ)
	$(CPP) -o $(BIN) $(MAINOBJ) $(SUB_OBJ) $(LIBRARIES)

clean: 
	rm -f $(BIN) $(SUB_OBJ) $(MAINOBJ)
